#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
脚本调度UI应用 - 主程序入口
"""

import sys
import os
import logging
import yaml
from PyQt6.QtWidgets import QApplication, QSplitter
from PyQt6.QtCore import QSettings

# 导入应用模块
from app.ui.main_window import MainWindow
from app.core.config import load_config
from app.utils.logger import setup_logger


def load_config():
    """加载配置文件"""
    try:
        with open("config.yaml", "r", encoding="utf-8") as f:
            config = yaml.safe_load(f)
        logging.info("已加载配置文件: config.yaml")
        return config
    except Exception as e:
        logging.critical(f"加载配置文件失败: {str(e)}")
        sys.exit(1)


def main():
    """主函数"""
    try:
        # 初始化日志系统
        setup_logger()
        
        # 加载配置
        config = load_config()
        
        # 创建应用
        app = QApplication(sys.argv)
        app.setApplicationName("脚本调度UI")
        app.setOrganizationName("FangYB")
        
        # 创建主窗口
        window = MainWindow(config)
        window.show()
        
        # 运行应用
        sys.exit(app.exec())
    except Exception as e:
        logging.critical(f"应用程序启动失败: {str(e)}", exc_info=True)
        sys.exit(1)


if __name__ == "__main__":
    main()